﻿using NLog;
using System;

namespace JX.Infrastructure.NLog
{
    /// <summary>
    /// NLog帮助类
    /// </summary>
    public class NLogHelper
	{
        private static readonly Logger log = LogManager.GetCurrentClassLogger();

        /// <summary>
        /// 记录Trace级别的日志
        /// </summary>
        /// <param name="msg"></param>
        /// <param name="exp"></param>
        public static void Trace(object msg, Exception exp = null)
        {
            if (exp == null)
                log.Trace(msg);
            else
                log.Trace(msg + "【发生异常】：" + exp.ToString());
        }
        /// <summary>
        /// 记录Debug级别的日志
        /// </summary>
        /// <param name="msg"></param>
        /// <param name="exp"></param>
        public static void Debug(object msg, Exception exp = null)
        {
            if (exp == null)
                log.Debug(msg);
            else
                log.Debug(msg + "【发生异常】：" + exp.ToString());
        }
        /// <summary>
        /// 记录Info级别的日志
        /// </summary>
        /// <param name="msg"></param>
        /// <param name="exp"></param>
        public static void Info(object msg, Exception exp = null)
        {
            if (exp == null)
                log.Info(msg);
            else
                log.Info(msg + "【发生异常】：" + exp.ToString());
        }

        /// <summary>
        /// 记录Warn级别的日志
        /// </summary>
        /// <param name="msg"></param>
        /// <param name="exp"></param>
        public static void Warn(object msg, Exception exp = null)
        {
            if (exp == null)
                log.Warn(msg);
            else
                log.Warn(msg + "【发生异常】：" + exp.ToString());
        }
        /// <summary>
        /// 记录Error级别的日志
        /// </summary>
        /// <param name="msg"></param>
        /// <param name="exp"></param>
        public static void Error(object msg, Exception exp = null)
        {
            if (exp == null)
                log.Error(msg);
            else
                log.Error(msg + "【发生异常】：" + exp.ToString());
        }
        /// <summary>
        /// 记录Fatal级别的日志
        /// </summary>
        /// <param name="msg"></param>
        /// <param name="exp"></param>
        public static void Fatal(object msg, Exception exp = null)
        {
            if (exp == null)
                log.Fatal(msg);
            else
                log.Fatal(msg + "【发生异常】：" + exp.ToString());
        }
    }
}
